<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h2>用户添加</h2>
<hr>
<form id="user-form">
    <input type="number" name="id" placeholder="请输入用户Id"><br>
    <input type="text" name="name" placeholder="请输入用户名"><br>
    <input type="number" name="age" placeholder="请输入用户年龄"><br>
    <input type="email" name="email" placeholder="请输入用户邮箱"><br>
    <button type="button">确认添加</button>
</form>

<script src="js/jquery-3.7.1.min.js"></script>
<script>
    $(function (){
        //
        $('button').on('click',function (){
            //获取表单数据转换
            let data=$('#user-form').serialize()
            $.get('/user/add',data,function (resp){
            if(resp){
                alert('添加成功')
                location.href='index.html'
            }
            else{
                alert('添加失败')}
        })
    })
    })
</script>
</body>
</html>